/*
 *  Description: BOAT XU SOFT FHSS
 *  Version: V1.00
 *  Author: boat xu
 *  Email: xifengzui@outlook.com
 *  Date: 2020-07-18 08:28:34
 *  LastEditTime: 2020-07-22 13:50:27
 */ 

#include "stdio.h"
#include "random.h"
#include "bsf.h"
#include "bsf_types.h"
#include "bsf_misc_com.h"
#if defined(WIN32) || defined(WIN64)
#include <windows.h>
#define sleep(n) Sleep(1000 * (n))
#else
#include <unistd.h>
#endif

b_u16_t timestamp = 0;
b_boolean isPktAri = b_false;
void sendPkt(unsigned char *pkt,unsigned char pktlen)
{
    int ii = 0;
    printf("        SendPkt[%d] = \n    {",pktlen);
    for(ii=0;ii<pktlen;ii++)
    {
        if((ii%10) == 0)
        {
            printf("\n    ");
        }
        printf("0x%x ",pkt[ii]);
    }
    printf("\n    }\n",pkt[ii]);
}


void setFreq(unsigned char freq)
{
    printf("        setFreq[%d]\n",freq);
}


b_u16_t getCurrentTimestamp(void)
{
    //printf("        getCurrentTimestamp[%d]\n",timestamp);
    return timestamp;
}


b_pktSendingStat sendingPktStatus(void)
{
    //printf("        sendingPktStatus\n");
    return b_pss_CompletedAck;
}


b_boolean isPktArrival(void)
{
    //printf("        isPktArrival[%d]\n" ,isPktAri);
    return isPktAri;
}

b_u8_t getPkt(b_u8_t* addr,b_u8_t len)
{
    //printf("        getPkt\n");
    bsf_miscComFillSync((bsf_payload*)addr);
    return 7;
}


void init(void)
{
    IsPktArrival = isPktArrival;
    SendPkt = sendPkt;
    SendingPktStatus = sendingPktStatus;
    GetPkt = getPkt;
    SetFreq = setFreq;
    GetCurrentTimestamp = getCurrentTimestamp;
}
int main()
{
    int ii = 0;
    int dd = 0;
    unsigned char *tmp;
    init();
    bsf_init();
    while(1)
    {
        dd++;
        bsf_do();
        timestamp +=rand()%100;
      /*  if(rand()%2 == 1)
        {
            isPktAri = b_true;
        }
        else
        {
            isPktAri = b_false;
        }*/
        sleep(1);
        bsf_sendPkt_Begin(&tmp);
        for(ii=0;ii<10;ii++)
        {
            tmp[ii] = ii;
        }
        bsf_sendPkt_End(dd,10);

    }
    return 0;
}